<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="店铺" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopName">
              <!-- <a-select
                v-model="model.shopName"
                style="width: 100%"
                placeholder="请选择店铺"
                @change="handleChange"
                :allowClear="allowClear"
              >
                <a-select-option v-for="(i, index) in shopOptions" :key="index" :value="i.value">
                  {{ i.label }}
                </a-select-option>
              </a-select> -->
              <j-search-select-tag v-model="model.shopName" :dict-options="shopOptions" placeholder="请选择店铺" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { deleteAction, getAction } from '@/api/manage'

export default {
  name: 'FinanceAmazonOrderDeleteForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      model: {
        shopName: '', //店铺名称
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
         shopName: [{ required: true, message: '请选择店铺名称' }],
      },
      url: {
        queryDelShopList: '/amazon/financeAmazonOrder/queryDelShopList', //可删除店铺列表
        // queryDelShopList: '/amazon/financeAmazonOrder/queryShopList',
        deleteByShop: '/amazon/financeAmazonOrder/deleteByShop', //删除店铺
      },
      shopOptions: [], //店铺名称数据
      allowClear: true, //是否支持清除
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    this.getListShop()
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    //选择店铺
    handleChange(value) {
      console.log(value)
      this.model.shopName = value
    },

    //获取店铺名称
    getListShop() {
      getAction(this.url.queryDelShopList)
        .then((res) => {
          if (res.success) {
            this.shopOptions = res.result
          } else {
            this.$message.error(res.message)
          }
        })
        .catch((err) => {
          this.$message.error(err.message)
        })
        .finally(() => {})
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true 
          this.$confirm({       
            title: '确定要通过该店铺删除吗?',
            onOk() {
               deleteAction(that.url.deleteByShop, { shopName: that.model.shopName }).then((res) => {
                 if (res.success) {
                    that.$message.success(res.message)  
                   that.$emit('ok')
                 } else {
                   that.$message.warning(res.message)
                 }
               }).finally(() => {
               that.confirmLoading = false;
             })
            },
            onCancel() {
              console.log('Cancel')
            },
            class: 'test',
          })
        }
      })
    },
  },
}
</script>